<script lang="ts" setup>
import { defineProps, onMounted, ref } from 'vue';

import {
  EchartsUI,
  type EchartsUIType,
  useEcharts,
} from '@vben/plugins/echarts';

const props = defineProps(['data']);
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

const dataList = props.data;

// console.log("dataList",dataList);
const xData: any = [];
const yData: any = [];
const yData2: any = [];
for (const item of dataList) {
  xData.push(item.days);
  yData.push(item.amount);
  yData2.push(item.count);
}

onMounted(() => {
  renderEcharts({
    grid: {
      bottom: 0,
      containLabel: true,
      left: '1%',
      right: '1%',
      top: '2 %',
    },
    series: [
      {
        name: '销售额(元)',
        areaStyle: {},
        data: yData,
        itemStyle: {
          color: '#5ab1ef',
        },
        smooth: true,
        type: 'line',
      },
      {
        name: '订单量',
        areaStyle: {},
        data: yData2,
        itemStyle: {
          color: '#019680',
        },
        smooth: true,
        type: 'line',
      },
    ],
    tooltip: {
      axisPointer: {
        lineStyle: {
          color: '#019680',
          width: 1,
        },
      },
      trigger: 'axis',
    },

    xAxis: {
      axisTick: {
        show: false,
      },
      boundaryGap: false,
      data: xData,
      splitLine: {
        lineStyle: {
          type: 'solid',
          width: 1,
        },
        show: true,
      },
      type: 'category',
    },
    yAxis: [
      {
        axisTick: {
          show: false,
        },
        splitArea: {
          show: true,
        },
        splitNumber: 4,
        type: 'value',
      },
    ],
  });
});
</script>

<template>
  <EchartsUI ref="chartRef" />
</template>
